<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

/* 配置添加路由 */
/*
return [
    '__pattern__' => [
        'name' => '\w+',
    ],
    '[hello]'     => [
        ':id'   => ['index/hello', ['method' => 'get'], ['id' => '\d+']],
        ':name' => ['index/hello', ['method' => 'post']],
    ],

];
*/

/* 动态添加路由引入 */
use think\Route;
// http://z.cn/api/v1/theme?ids=1,2,3&XDEBUG_SESSION_START=14416
// http://z.cn/api/v1/theme/4&XDEBUG_SESSION_START=17643
// http://z.cn/api/v1/product/recent?count=3&
// http://z.cn/api/v1/product/by_category?id=3
// http://z.cn/api/v1/category/all
// http://z.cn/api/v1/token/user
// http://z.cn/api/v1/address /post
// body: {"name":"qiyue","mobile":"18888888888","province":"山西省","city":"临汾市","country":"五村镇","detail":"狮子王哈哈"}

Route::get('api/:version/banner/:id', 'api/:version.Banner/getBanner');

Route::get('api/:version/theme', 'api/:version.Theme/getSimpleList');
Route::get('api/:version/theme/:id', 'api/:version.Theme/getComplexOne');

Route::get('api/:version/product/by_category', 'api/:version.Product/getAllInCategory');
Route::get('api/:version/product/:id', 'api/:version.Product/getOne', [], ['id'=>'\d+']); // 限定参数的规则
Route::get('api/:version/product/recent', 'api/:version.Product/getRecent');

Route::post('api/:version/address', 'api/:version.Address/createOrUpdateAddress');

// 路由分组
//Route::group('api/:version/product', function () {
//    Route::get('/recent', 'api/:version.Product/getRecent');
//    Route::get('/by_category', 'api/:version.Product/getAllInCategory');
//    Route::get('/:id', 'api/:version.Product/getOne', [], ['id'=>'\d+']);
//});

Route::get('api/:version/category/all', 'api/:version.Category/getAllCategories');

Route::post('api/:version/token/user', 'api/:version.Token/getToken');

/**
 * tp5 是顺序传参
 * :id - recent 顺序变化 recent 路由会报错，即匹配不到 recent
 */
/**
 * 路由传参
 * 1. z.cn/hello/123 url 路径传参数 hello/:id 任意自定义变量
 * 2. z.cn/hello?name=aaa
 */
Route::rule('hello/:id', 'sample/Test/hello', 'GET | POST', ['https'=>false]);

/******************************************************
 * 定义路由
 * z.cn/hello - 定义的路由访问方式 一旦 定义 路由，PATH_INFO 失效，对于相同的路径
 * z.cn/sample/Test/hello - PATH_INFO 访问方式
 */
//Route::rule('hello', 'sample/Test/hello', 'GET | POST', ['https'=>false]);

/******************************************************
 * 其他快捷注册路由方式
 */
//Route::get('hello', 'sample/Test/hello');
//Route::POST('hello', 'sample/Test/hello');

